package com.wicket.okrframework.biz.service.nb;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil;
import com.wicket.okrcomponent.common.annotations.BanAuto;
import com.wicket.okrframework.biz.service.dto.req.CheckCaptchaValidReqDto;
import com.wicket.okrframework.biz.service.dto.req.QueryCollectionRemoveDuplicateDataListReqDto;
import com.wicket.okrframework.biz.service.dto.req.QueryCollectionRemoveExistingDataListReqDto;
import com.wicket.okrframework.biz.service.dto.req.QueryMemberCollectionDataListReqDto;
import com.wicket.okrframework.biz.service.dto.res.*;
import org.apache.skywalking.apm.toolkit.trace.Tag;
import org.apache.skywalking.apm.toolkit.trace.Tags;
import org.apache.skywalking.apm.toolkit.trace.Trace;
import org.springframework.stereotype.Service;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
import com.wicket.okrframework.biz.service.dto.req.QueryReceiveFieldDetailReqDto;

/**
 * @author ： 手工接入方法
 * @since 2022/5/28 15:32
 *
 *
 * @version 1.0
 */
@Service
public class NbMember {
    /**
     * code:collectionRemoveExistingData
     * name:查询去重部门员工列表（特殊方法）
     * desc:undefined
     **/
    @BanAuto
    @Trace(operationName = "查询去重部门员工列表（特殊方法）")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    public QueryCollectionRemoveDuplicateDataListRespDto queryCollectionRemoveDuplicateDataList(QueryCollectionRemoveDuplicateDataListReqDto reqDto) {
        QueryCollectionRemoveDuplicateDataListRespDto retData = new QueryCollectionRemoveDuplicateDataListRespDto();
        retData.setBeginMemberList(new ArrayList<>());
        List<BeginMemberDto> memberList = new ArrayList<>(reqDto.getBeginMemberList());
        for (BeginMemberDto oneMember : reqDto.getBeginMemberList()) {
            for (String id : reqDto.getOrgInductionRecordList()) {
                if (oneMember.getOriginalRoleMemberId().equals(id)) {
                    memberList.remove(oneMember);
                }
            }
        }
        retData.setBeginMemberList(memberList);
        return retData;
    }

    /**
     * code:collectionRemoveExistingData
     * name:查询可用空间管理员（合并去除重复特殊方法）
     * desc:undefined
     **/
    @BanAuto
    @Trace(operationName = "查询可用空间管理员（合并去除重复特殊方法）")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    public QueryCollectionRemoveExistingDataListRespDto queryCollectionRemoveExistingDataList(QueryCollectionRemoveExistingDataListReqDto reqDto) {
        QueryCollectionRemoveExistingDataListRespDto retData = new QueryCollectionRemoveExistingDataListRespDto();
        List<String> filetedStaffList = new ArrayList<>(reqDto.getStaffBeginMemberList());
        for (String staff : reqDto.getStaffBeginMemberList()) {
            for (String role : reqDto.getRoleRelList()) {
                if (staff.equals(role)) {
                    filetedStaffList.remove(staff);
                }
            }
        }
        retData.setStaffBeginMemberList(filetedStaffList);
        return retData;
    }

    /**
     * code:checkCaptchaValid
     * name:M1-检测验证码是否有效
     * desc:undefined
     **/
    @BanAuto
    @Trace(operationName = "M1-检测验证码是否有效")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    public CheckCaptchaValidRespDto checkCaptchaValid(CheckCaptchaValidReqDto reqDto) {
        CheckCaptchaValidRespDto retData = new CheckCaptchaValidRespDto();
        retData.setIsInvalid("TRUE");
        return retData;
    }

    /**
     * code:collectionNData
     * name:M-查询成员集合取x条数据（特殊方法）
     * desc:undefined
     **/
    @BanAuto
    @Trace(operationName = "M-查询成员集合取x条数据（特殊方法）")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    public QueryMemberCollectionDataListRespDto queryMemberCollectionDataList(QueryMemberCollectionDataListReqDto reqDto) {
        QueryMemberCollectionDataListRespDto retData = new QueryMemberCollectionDataListRespDto();
        if (ObjectUtil.isNull(reqDto) || CollUtil.isEmpty(reqDto.getBeginMemberList())) {
            retData.setBeginMemberList(new ArrayList<>());
            return retData;
        }
        if (reqDto.getBeginMemberList().size() < reqDto.getCollectionData()) {
            retData.setBeginMemberList(reqDto.getBeginMemberList());
        } else {
            retData.setBeginMemberList(reqDto.getBeginMemberList().subList(0, reqDto.getCollectionData().intValue()));
        }
        return retData;
    }
/**
      * code:receptionService
      * name:M1-有值可操作（工号可用）
      * desc:undefined
      * gen by moon at 8/13/2022, 11:44:29 PM
      * 
      **/
     @Trace(operationName = "M1-有值可操作（工号可用）")
     @Tags({@Tag(key = "参数",value = "arg[0]"),
     @Tag(key = "返回值",value = "returnedObj")})
      public QueryReceiveFieldDetailRespDto queryReceiveFieldDetail(QueryReceiveFieldDetailReqDto reqDto) {
         QueryReceiveFieldDetailRespDto retData =  BeanUtil.toBean(reqDto,QueryReceiveFieldDetailRespDto.class);
         Field[] declaredFields = retData.getClass().getDeclaredFields();
         for(Field field : declaredFields){
             try {
                 field.setAccessible(true);
                 Object fieldValue = field.get(retData);
                 if(fieldValue==null){
                     if(field.getType().equals(String.class)){
                         field.set(retData,"0");
                     }else if(field.getType().equals(Long.class)){
                         field.set(retData,0L);
                     }else if(field.getType().equals(Long.class)){
                         field.set(retData,0l);
                     }
                 }
             } catch (IllegalAccessException e) {
                 e.printStackTrace();
             }
         }
         return retData;
      }
    //手工接入方法
}
